//
//  QPSaccountStore.m
//  Candy2
//
//  Created by Aiwa on 11/2/15.
//  Copyright © 2015 Aiwa. All rights reserved.
//

#import "QPSaccountStore.h"

static QPSaccountStore* instanceOnce = nil;
static QPSaccountStore* instanceOnce;

@interface QPSaccountStore()

@end

@implementation QPSaccountStore

+ (QPSaccountStore*)sharedInstance{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instanceOnce = [[self alloc] init];
    });
    return instanceOnce;
}

- (void)saveAccessToken:(NSString*) accessToken
{
    [[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:@"accessToken"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
- (NSString*)getAccessToken
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"accessToken"];
}
- (void)removeAccessToken
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"accessToken"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)saveIsScoreOpen:(BOOL) isScoreOpen
{
    [[NSUserDefaults standardUserDefaults] setBool:isScoreOpen forKey:@"isScoreOpen"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
- (BOOL)getIsScoreOpen
{
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"isScoreOpen"];
}

#pragma mark - 得到时间戳字符串
+ (NSString *)getTsString
{
    NSDate * now = [NSDate date];
    NSTimeInterval diff = [now timeIntervalSince1970];
    NSString * diffString = [NSString stringWithFormat:@"%ld",(long)diff];
    return diffString;
}

- (UIWindow *)getCurrentWindow {
    NSArray *windows = [UIApplication sharedApplication].windows;
    for (UIWindow *window in [windows reverseObjectEnumerator]) {
        if ([window isKindOfClass:[UIWindow class]] && CGRectEqualToRect(window.bounds, [UIScreen mainScreen].bounds)) {
            return window;
        }
    }
    return [UIApplication sharedApplication].keyWindow;
}

//获取当前时间戳
- (NSString *)currentTimeStr {
    NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];//获取当前时间0秒后的时间
    NSTimeInterval time=[date timeIntervalSince1970];// *1000 是精确到毫秒，不乘就是精确到秒
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time];
    return timeString;
}

@end
